<template>
	<view class="page index">
		<view class="form">
			<!-- <common-input
			  title="跟进客户" 
				placeholder="请选择" 
				v-model="company"
				:border-bottom="false"
				:disabled="true"
			>
			</common-input> -->
			<common-input
			  title="跟进项目" 
				placeholder="请选择" 
				v-model="project"
				:border-bottom="false"
				:disabled="true"
			>
			</common-input>
			<picker mode="selector" :value="typeIndex" :range="typeList" @change="selectType">
				<view class="picker">
					<common-input 
					  title="跟进方式" 
					  placeholder="请选择跟进方式" 
					  v-model="typeIndex < 0 ? '' : typeList[typeIndex]" 
					  :select="true" 
					  :disabled="true" 
					>
					</common-input>
				</view>
			</picker>
			<!-- <common-input
			  title="联系人" 
				placeholder="请选择项目联系人" 
				v-model="contact"
				:disabled="true"
			>
			</common-input> -->
			<!-- <common-input
			  title="本次跟进时间" 
				placeholder="请填写跟进时间" 
				v-model="time"
				:boder-top="false"
			>
			</common-input> -->
			<view class="text">
				<view class="title">
					<view>
						本次跟进内容
					</view>
					<view class="require"></view>
				</view>
				<textarea v-model="content" placeholder="请输入" placeholder-class="place"></textarea>
			</view>
			<view class="picker" @click="$refs.followTime.open()">
				<common-input
				  title="计划下次跟进时间" 
					placeholder="请填写下次跟进时间" 
					v-model="nextTime"
					:boder-top="false"
					:require="false"
					:disabled="true"
				>
				</common-input>
			</view>
			<update-file title="跟进凭证" @update="updatefiles"></update-file>
		</view>
		<view class="footer">
			<button @click="save">保存</button>
		</view>
		<!-- 选择下次跟进时间 -->
		<uni-popup ref="followTime" type="bottom">
			<view class="model-popup">
				<view class="top">
					<view class="title">
						选择下次跟进时间
					</view>
					<view class="content">
						<uni-datetime-picker type="datetime" v-model="datetimesingle"/>
					</view>
				</view>
				<view class="bottom">
					<button class="cancle" @click="$refs.followTime.close()">取消</button>
					<button class="confire" @click="confireTime">确定</button>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import commonInput from "@/components/commonInput.vue";
	import updateFile from "@/components/updateFile.vue";
	import {createFollowApi} from "@/api/follow_api.js";
	export default{
		data() {
			return{
				project: '',
				projectId: 0,
				typeIndex:0,
				typeList:['打电话', '邮件', '上门拜访', '微信/钉钉'],
				// contact:'',
				// time: '',
				content:'',
				nextTime:'',
				picUrls: [],
				fileUrls: [],
				datetimesingle:''
			}
		},
		components: {
			commonInput,
			updateFile
		},
		onLoad(e) {
			console.log(e);
			this.project = e.name;
			this.projectId = e.id;
		},
		methods:{
			// 文件
			updatefiles(e){
			  this.picUrls = e.filter((item) => {
					return item.type == 'image'
				});
				this.picUrls = this.picUrls.map((item) => item.path);
				this.fileUrls = e.filter((item) => {
					return item.type == 'file'
				});
				this.fileUrls = this.fileUrls.map((item) => item.path);
				console.log(this.picUrls, this.fileUrls)
			},
			// 下次跟进时间
			confireTime(){
				this.nextTime = this.datetimesingle;
				this.$refs.followTime.close();
			},
			save(){
				if(this.content == ''){
					uni.showToast({
						icon: 'none',
						title: '跟进内容不能为空'
					})
				}
				uni.showLoading({
					mask: true,
					title: '加载中...'
				})
				createFollowApi({
					bizType: 9,
					bizId: this.projectId,
					type: Number(this.typeIndex) + 1,
					content: this.content,
					nextTime: Date.parse(this.nextTime),
					picUrls: this.picUrls,
					fileUrls: this.fileUrls
				}).then(() => {
					uni.hideLoading();
					uni.showToast({
						icon: 'success',
						title: '创建成功！'
					})
					setTimeout(() => {
						uni.navigateBack();
					},1500)
				}).catch(() => {
					uni.hideLoading();
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/common/style/customicons.scss";
	.index{
		padding: 24rpx 0;
		@include flex-c;
		.form{
			flex: 1 0 0;
			overflow: auto;
			.text{
				border-bottom: 4rpx #e5e5e5 solid;
				padding: 12rpx 30rpx;
				.title{
					font-size: 28rpx;
					color: #101010;
					padding: 0 0 16rpx;
					display: flex;
					align-items: center;
					.require{
					  height: 28rpx;
					  width: 6rpx;
					  background-color: #c24135;
					  margin-left: 10rpx;
				  }
				}
				textarea{
					font-size: 28rpx;
					color: #909090;
					height: 125rpx;
				}
				.place{
					font-size: 28rpx;
					color: #909090;
				}
			}
			&::-webkit-scrollbar{
				display: none;
			}
		}
		.footer{
			flex: 0 0 auto;
			padding: 24rpx 130rpx;
			button{
				@include button;
				background-color: #198AFA;
				color: #fff;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 28rpx;
				width: 100%;
			}
		}
		.model-popup{
			background-color: #fff;
			@include box;
			border-radius: 16rpx;
			.top{
				padding: 24rpx 40rpx 56rpx;
				.title{
					color: #101010;
					font-size: 36rpx;
					text-align: center;
					padding: 0 0 34rpx;
				}
				.content{
					height: 200rpx;
					@include flex-r-center-center;
				}
			}
			.bottom{
				@include flex-r;
				border-top: 4rpx #F0F0F2 solid;
				button{
					@include button;
					width: 50%;
					height: 90rpx;
					line-height: 90rpx;
					font-size: 32rpx;
					background-color: #fff;
					border-radius: 0;
				}
				.cancle{
					color: #BBBBBB;
					border-right: 4rpx #F0F0F2 solid;
				}
				.confire{
					color: #4095E5;
				}
			}
		}
	}
</style>